/**
 * @fileoverview This file contains the odfStreamConverterFactory object. This object implements the nsIFactory
 *               interface. It is the components factory, which through its own member function, createInstance( ),
 *               constructs and returns an instance of the complete component (if the iid parameter is specified and is
 *               the correct interface).
 *
 * Some of the codes used were based on the following existing addons for Firefox.
 * 1. ODFReader 0.2.1 (Updated October 24, 2006)
 *     https://addons.mozilla.org/en-US/firefox/addon/1888
 *    @author Talin(C) 2005-6
 *    @author Alex Hudson (C) 2006
 *    Released under the MPL/LGPL/GPL tri-license
 * 2. OdfPlugin 0.17b (Updated October 23, 2007)
 *     https://addons.mozilla.org/en-US/firefox/addon/5907
 *    @author David Staessens (02-05-07)
 * - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =
 *
 * @author last modified by: Jamie L. Vargas (2009/08/03)
 * Released under GPLv3. See file gpl-3.0.txt included in this package.
 */

/* Factory Object: A JavaScript object that implements the nsIFactory interface. */
var odfStreamConverterFactory = new Object();

/**
 * Creates an instance of the OdfStreamConverter object, if called with right Interface ID
 *
 * @param {nsISupports} aOuter Pointer to a component that wishes to be aggregated in the resulting instance. This can
 *            be nsnull if no aggregation is requested.
 * @param {nsIIDRef} aIID The interface type to be returned. i.e. the IID of the interface being requested in the
 *            component which is being currently created.
 * @return odfStreamConverter - [iid_is(aIID),retval] out {nsQIResult} aResult The resulting interface pointer. i.e.
 *         pointer to the newly created instance, if successful.
 *
 * @throws NS_ERROR_NO_INTERFACE Indicates that the requested interface is not supported.
 * @throws NS_ERROR_NO_AGGREGATION Indicates that aggregation is not supported.
 */
odfStreamConverterFactory.createInstance = function(aOuter, aIID) {
    logDebug("odfStreamConverterFactory::createInstance",
                    "Trying to create instance of the odfStreamConverter with IID " + aIID);

    if (aOuter != null) {
        throw Components.results.NS_ERROR_NO_AGGREGATION;
    } // this class doesn't allow aggregation

    // These 4 interfaces are implemented and usable
    if (aIID.equals(Ci.nsISupports) || aIID.equals(Ci.nsIStreamConverter)
            || aIID.equals(Ci.nsIStreamListener) || aIID.equals(Ci.nsIRequestObserver)) {

        if (!oSCLoaded) {
            throw Components.results.NS_ERROR_NO_INTERFACE; //NS_ERROR_NOT_INITIALIZED;
        } else {
            return new odfStreamConverter();
        }
    }

    throw Components.results.NS_ERROR_INVALID_ARG;
}

var oSCFLoaded = true;
